#include <iostream>

#include <functional>

#include <nemesis.h>
#include <nemesis.html.h>

#include <nemesis.app.Application.h>

class Test : public nemesis::app::Application {
public:
   Test ();
   
private:
   void run () throw (nemesis::RuntimeException);      
};

using namespace std;

int main (int argc, const char** argv)
{
   CommandLine& commandLine (CommandLine::instanciate ());
   Test test;

   nemesis::html::functions::initialize ();

   try {
      commandLine.initialize (argv, argc);
      commandLine.verify ();
      test.start ();
   }
   catch (Exception& ex) {
      cout << ex.asString () << endl;
   }
   
   return 0;
}

Test::Test () : 
   nemesis::app::Application ("testfunctions", "Comprobacin del sistema de trazas", "1.0") 
{
   CommandLine& commandLine (CommandLine::instanciate ());
      
   commandLine.add ("document", CommandLine::Argument::Mandatory, "Nombre del documento XML");
}

void Test::run () 
   throw (RuntimeException)
{
   CommandLine& commandLine (CommandLine::instanciate ());

   html::DocumentFile htmlDoc;
   html::Parser parser;
   html::Compiler htmlCompiler;

   htmlDoc.initialize (commandLine.getValue ("document"));

   cout << "Documento: " << endl << htmlDoc.getContent () << endl << endl;

   const html::Node* root = parser.apply (htmlDoc);
   const html::Node* node;

   for (html::Node::const_iterator ii = root->begin (), maxii = root->end (); ii != maxii; ii ++) {
      node = html::Node::node (ii);
      cout << "Nombre: " << node->getName () << endl;
   } 

   cout << "html::Compiler: " << endl << htmlCompiler.apply (root) << endl << endl;
}

